package com.mobile.manager.service.impl;

import com.mobile.manager.dao.IDeviceDao;
import com.mobile.manager.pojo.Device;
import com.mobile.manager.service.IDeviceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by zhangdi on 16/4/24.
 */
@Service("deviceService")
public class DeviceServiceImpl implements IDeviceService {

    @Resource
    private IDeviceDao deviceDao;

    public Device getDeviceById(int id) {
        return this.deviceDao.selectByPrimaryKey(id);
    }

    @Override
    public List<Device> getAllDevice() {
        return this.deviceDao.selectAllDevice();
    }

    @Override
    public int insertDevice(Device device) {
        return this.deviceDao.insertDevice(device);
    }

    @Override
    public List<Device> searchDevice(Device device) {
        if(device.getGroup_info().equals("1")){
            device.setGroup_info("平台-APP");
        }
        if(device.getGroup_info().equals("2")){
            device.setGroup_info("平台-新业务");
        }
        if(device.getGroup_info().equals("3")){
            device.setGroup_info("平台-三方");
        }
        if(device.getGroup_info().equals("4")){
            device.setGroup_info("自营-家政");
        }
        if(device.getGroup_info().equals("5")){
            device.setGroup_info("自营-丽人");
        }
        if(device.getGroup_info().equals("6")){
            device.setGroup_info("自营-速运");
        }
        if(device.getGroup_info().equals("7")){
            device.setGroup_info("中台-中台");
        }
        if(device.getOs().equals("1")){
            device.setOs("Android");
        }
        if(device.getOs().equals("2")){
            device.setOs("IOS");
        }
        return this.deviceDao.searchDevice(device);
    }

    @Override
    public int updateDevice(Device device) {
        return this.deviceDao.updateByPrimaryKey(device);
    }

    @Override
    public int borrowDevice(Device device) {
        return this.deviceDao.borrowDevice(device);
    }

    @Override
    public String getCountOfDeviceByOS(Device device) {
        return this.deviceDao.getCountOfDeviceByOS(device);
    }


}
